fix: suppress JSON output for describe affected --upload#2284
Conversation
When --upload is used, the full affected stacks JSON is no longer dumped to the console by default. Use --verbose to see it. The success message now includes a count of affected components. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Dependency Review✅ No vulnerabilities or license issues found.Snapshot WarningsEnsure that dependencies are being submitted on PR branches and consider enabling retry-on-snapshot-warnings. See the documentation for more information and troubleshooting advice. Scanned FilesNone |
📝 WalkthroughWalkthroughSuppresses the large "Affected components and stacks" console view during uploads unless verbose mode or an output file is requested, and changes the upload success message to include the number of affected components. Adds unit tests covering upload/output control flow and upload payload assertions. Changes
Sequence Diagram(s)(omitted) Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add two tests proving that: - Upload path is reached when output is suppressed (Upload=true, Verbose=false) - Output is shown when verbose is enabled (Upload=true, Verbose=true) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
🧹 Nitpick comments (1)
internal/exec/describe_affected_test.go (1)
2079-2168: Consider adding a test forOutputFilescenario.The new conditional in
uploadableQueryhas three branches:!args.Upload,args.Verbose, andargs.OutputFile != "". The tests cover the first two but not the third. A test verifying that output is shown whenUpload=true,Verbose=false, andOutputFileis set would complete the coverage.Example test case
// TestUploadShowsOutputWhenFileSet verifies that when --upload and --file are both set, // the JSON output is written to file (printOrWriteToFile is called). func TestUploadShowsOutputWhenFileSet(t *testing.T) { printCalled := false d := describeAffectedExec{ atmosConfig: &schema.AtmosConfiguration{}, printOrWriteToFile: func(atmosConfig *schema.AtmosConfiguration, format, file string, data any) error { printCalled = true return nil }, IsTTYSupportForStdout: func() bool { return false }, pageCreator: pager.New(), } headRef := plumbing.NewHashReference("refs/heads/feature", plumbing.NewHash("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")) baseRef := plumbing.NewHashReference("refs/heads/main", plumbing.NewHash("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb")) affected := []schema.Affected{ {Component: "vpc", Stack: "dev"}, } err := d.uploadableQuery( &DescribeAffectedCmdArgs{ Upload: true, Verbose: false, OutputFile: "/tmp/affected.json", Format: "json", CIEventType: "pull_request", CLIConfig: &schema.AtmosConfiguration{}, }, "https://github.com/example/repo.git", headRef, baseRef, affected, ) assert.True(t, printCalled, "printOrWriteToFile should be called when --upload and --file are both set") assert.NoError(t, err) }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@internal/exec/describe_affected_test.go` around lines 2079 - 2168, The test suite is missing coverage for the upload branch when OutputFile is provided; add a new unit test that calls describeAffectedExec.uploadableQuery with DescribeAffectedCmdArgs{Upload:true, Verbose:false, OutputFile:"/tmp/affected.json", Format:"json", CIEventType:"pull_request", CLIConfig:...} using a describeAffectedExec whose printOrWriteToFile stub flips a boolean, then assert printOrWriteToFile was called and that uploadableQuery returns no error; reference the same setup as TestUploadSuppressesOutputButStillUploads/TestUploadShowsOutputWhenVerbose (headRef, baseRef, affected, IsTTYSupportForStdout, pageCreator) to keep tests consistent.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@internal/exec/describe_affected_test.go`:
- Around line 2079-2168: The test suite is missing coverage for the upload
branch when OutputFile is provided; add a new unit test that calls
describeAffectedExec.uploadableQuery with DescribeAffectedCmdArgs{Upload:true,
Verbose:false, OutputFile:"/tmp/affected.json", Format:"json",
CIEventType:"pull_request", CLIConfig:...} using a describeAffectedExec whose
printOrWriteToFile stub flips a boolean, then assert printOrWriteToFile was
called and that uploadableQuery returns no error; reference the same setup as
TestUploadSuppressesOutputButStillUploads/TestUploadShowsOutputWhenVerbose
(headRef, baseRef, affected, IsTTYSupportForStdout, pageCreator) to keep tests
consistent.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: a8cc9315-6a41-4eab-a632-b60332adc9fe
📒 Files selected for processing (2)
internal/exec/describe_affected.gointernal/exec/describe_affected_test.go
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2284 +/- ##
==========================================
+ Coverage 77.19% 77.23% +0.04%
==========================================
Files 1045 1045
Lines 98388 98389 +1
==========================================
+ Hits 75951 75995 +44
+ Misses 18184 18141 -43
Partials 4253 4253
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
internal/exec/describe_affected_test.go (1)
2100-2186: Consolidate upload output mode tests into table-driven cases.These two tests are the same harness with mode toggles (
Verbosefalse/true). A table-driven test will reduce duplication and make future branches easier to add.♻️ Proposed refactor sketch
+func TestUploadOutputModes(t *testing.T) { + cases := []struct { + name string + verbose bool + wantCalls int + }{ + {name: "suppressed when upload without verbose", verbose: false, wantCalls: 0}, + {name: "shown when upload with verbose", verbose: true, wantCalls: 1}, + } + + for _, tc := range cases { + t.Run(tc.name, func(t *testing.T) { + calls := 0 + d := describeAffectedExec{ + atmosConfig: &schema.AtmosConfiguration{}, + printOrWriteToFile: func(*schema.AtmosConfiguration, string, string, any) error { + calls++ + return nil + }, + IsTTYSupportForStdout: func() bool { return false }, + pageCreator: pager.New(), + } + // ... invoke uploadableQuery with tc.verbose ... + assert.Equal(t, tc.wantCalls, calls) + }) + } +}As per coding guidelines, "Use table-driven tests for testing multiple scenarios in Go."
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@internal/exec/describe_affected_test.go` around lines 2100 - 2186, Combine the two near-identical tests TestUploadSuppressesOutputButStillUploads and TestUploadShowsOutputWhenVerbose into a single table-driven test (e.g., TestUploadOutputModes) that iterates cases for Verbose=false and Verbose=true; for each case create the describeAffectedExec with the same printOrWriteToFile stub, IsTTYSupportForStdout, pageCreator, headRef/baseRef and affected slice, call uploadableQuery with fields driven from the table row, and in a t.Run subtest assert whether printCalled matches the expected value and that err is nil; this reduces duplication and keeps the same assertions and setup while using table rows to add future cases.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@internal/exec/describe_affected_test.go`:
- Around line 2218-2250: The test only checks that the printOrWriteToFile hook
was called but not what arguments were passed; modify the closure passed as
printOrWriteToFile in the test for uploadableQuery to capture the incoming
format and file parameters (e.g., store them in local vars like gotFormat,
gotFile) and return nil, then after calling d.uploadableQuery assert that
gotFile equals the DescribeAffectedCmdArgs.OutputFile value and gotFormat equals
"json" (and optionally assert data is non-nil or contains expected content);
update references to the closure and the
DescribeAffectedCmdArgs.OutputFile/Format expectations accordingly so the
OutputFile branch is validated directly.
---
Nitpick comments:
In `@internal/exec/describe_affected_test.go`:
- Around line 2100-2186: Combine the two near-identical tests
TestUploadSuppressesOutputButStillUploads and TestUploadShowsOutputWhenVerbose
into a single table-driven test (e.g., TestUploadOutputModes) that iterates
cases for Verbose=false and Verbose=true; for each case create the
describeAffectedExec with the same printOrWriteToFile stub,
IsTTYSupportForStdout, pageCreator, headRef/baseRef and affected slice, call
uploadableQuery with fields driven from the table row, and in a t.Run subtest
assert whether printCalled matches the expected value and that err is nil; this
reduces duplication and keeps the same assertions and setup while using table
rows to add future cases.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 43540841-5eb4-413e-b778-590aef0d10f9
📒 Files selected for processing (1)
internal/exec/describe_affected_test.go
There was a problem hiding this comment.
🧹 Nitpick comments (1)
internal/exec/describe_affected_test.go (1)
2728-2732: Conditional assertion may weaken test guarantees.The
if describe.SHA == ""branch makes this test pass for two different outcomes. For a pull_request event with the given payload, the expected behavior should be deterministic. If the provider can legitimately return either Ref or SHA, consider splitting into separate sub-tests or documenting why both outcomes are acceptable.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@internal/exec/describe_affected_test.go` around lines 2728 - 2732, The test currently allows two different outcomes by using "if describe.SHA == \"\"" which weakens guarantees; change the test to be deterministic by either asserting exactly the expected field (Ref or SHA) for the specific pull_request payload or split into two explicit sub-tests that validate each allowed provider behavior separately: locate the test that reads the describe variable (references to describe.SHA and describe.Ref) and replace the conditional with one of two fixes — (A) assert the single expected value (e.g., require.Equal on describe.SHA or describe.Ref) for this payload, or (B) create two sub-tests (t.Run(\"returns-sha\", ...) and t.Run(\"returns-ref\", ...)) each with a fixture or mocked provider that deterministically returns SHA or Ref and assert the corresponding field; ensure the assertions are precise (use require/expect) and add a short comment explaining why both behaviors are tested if you choose option B.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@internal/exec/describe_affected_test.go`:
- Around line 2728-2732: The test currently allows two different outcomes by
using "if describe.SHA == \"\"" which weakens guarantees; change the test to be
deterministic by either asserting exactly the expected field (Ref or SHA) for
the specific pull_request payload or split into two explicit sub-tests that
validate each allowed provider behavior separately: locate the test that reads
the describe variable (references to describe.SHA and describe.Ref) and replace
the conditional with one of two fixes — (A) assert the single expected value
(e.g., require.Equal on describe.SHA or describe.Ref) for this payload, or (B)
create two sub-tests (t.Run(\"returns-sha\", ...) and t.Run(\"returns-ref\",
...)) each with a fixture or mocked provider that deterministically returns SHA
or Ref and assert the corresponding field; ensure the assertions are precise
(use require/expect) and add a short comment explaining why both behaviors are
tested if you choose option B.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: b50ca35e-c0b6-4c77-9203-9f5844935593
📒 Files selected for processing (1)
internal/exec/describe_affected_test.go
|
These changes were released in v1.215.0-rc.2. |
what
--uploadis used withatmos describe affected, the full affected stacks JSON is no longer dumped to the console by default--verboseto see the JSON output, or--fileto write it to a filewhy
--verboseor--filereferences
N/A
Summary by CodeRabbit
Bug Fixes
Tests